﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.WebTesting;
using Microsoft.VisualStudio.TestTools.WebTesting.Rules;

namespace QA.TFS.Rules.Extraction
{

  [DisplayName("If fails Extraction Text Rule")]
  [Description("Output if whether or not the Extraction Text fails")]
  public class ExtractTextFailsOut : ExtractText
  {

    private string failsContextParameterName;
    [Description("Context Parameter Name where fail result will write it")]
    public string FailsContextParameterName
    {
      get { return failsContextParameterName; }
      set { failsContextParameterName = value; }
    }

    [DisplayName("If fails Extraction Text Rule")]
    [Description("Output if whether or not the Extraction Text fails")]
    public override void Extract(object sender, ExtractionEventArgs e)
    {
      base.Extract(sender, e);
      if (e.Success)
      {
        e.WebTest.Context.Add(failsContextParameterName, "true");
      }
      else
      {
        e.WebTest.Context.Add(failsContextParameterName, "false");
        e.Success = true;
      }
    }

  }
}
